package com.tz.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="bs_category")
public class Category implements Serializable{
	
	private static final long serialVersionUID = 2817447363812934391L;

	private long id;
	
	private String name;
	
	private Category parent;
	
	private List<Category> children;
	
	public Category() {
		
	}

	public Category(String name, Category parent, List<Category> children) {
		super();
		this.name = name;
		this.parent = parent;
		this.children = children;
	}
	
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToOne
	@JoinColumn(name="c_parent_id")
	public Category getParent() {
		return parent;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}
	@OneToMany(mappedBy="parent" ,fetch=FetchType.EAGER)
	public List<Category> getChildren() {
		return children;
	}

	public void setChildren(List<Category> children) {
		this.children = children;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Category [id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", parent=");
		builder.append(parent);
		builder.append("]");
		return builder.toString();
	}
	
	
	

}
